package com.system.server;

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;

public class UserUI extends Application {
    public void start(Stage stage)
    {
        GridPane pane=new GridPane();
        pane.setAlignment(Pos.BASELINE_CENTER);
        pane.setPadding(new Insets(50,50,50,50));
        pane.setHgap(10);
        pane.setVgap(10);

        Label TitleLabel=new Label("用户信息录入");
        TitleLabel.setFont(Font.font("用户信息录入", FontWeight.BOLD,20));
        pane.add(TitleLabel,0,0);
        Label userName_label=new Label("用户名: ");
        pane.add(userName_label,0,1);
        TextField user_name=new TextField();
        pane.add(user_name,1,1);
        Label pwd_label=new Label("用户密码: ");
        pane.add(pwd_label,0,2);
        TextField user_pwd=new TextField();
        pane.add(user_pwd,1,2);
        Label user_nick_label=new Label("用户昵称: ");
        pane.add(user_nick_label,0,3);
        TextField user_nick=new TextField();
        pane.add(user_nick,1,3);
        Label email_label=new Label("用户邮箱: ");
        pane.add(email_label,0,4);
        TextField user_email=new TextField();
        pane.add(user_email,1,4);
        Label address_label=new Label("用户地址: ");
        pane.add(address_label,0,5);
        TextField user_address=new TextField();
        pane.add(user_address,1,5);
        Label money_label=new Label("用户余额: ");
        pane.add(money_label,0,6);
        TextField user_money=new TextField();
        pane.add(user_money,1,6);


        Button addBtn=new Button("添加");
        Button exitBtn=new Button("退出");
        pane.add(addBtn,0,8);
        pane.add(exitBtn,1,8);

        addBtn.setOnAction(actionEvent -> {
            User user=new User();
            user.setUser_name(user_name.getText());
            user.setUser_password(user_pwd.getText());
            user.setUser_nickName(user_nick.getText());
            user.setUser_email(user_email.getText());
            user.setUser_address(user_address.getText());
            user.setUser_money(Double.parseDouble(user_money.getText()));
            UserDAO.insert(user);
            user_name.clear();
            user_pwd.clear();
            user_nick.clear();
            user_email.clear();
            user_address.clear();
            user_money.clear();
        });
        exitBtn.setOnAction(actionEvent -> {
            stage.close();
        });

        Scene scene=new Scene(pane);
        stage.setScene(scene);
        stage.setTitle("添加用户");
        stage.show();
    }
}
